﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using FunMazeEngine;

namespace FunMazeClient
{
    public delegate void BackUpServerIPUpdate(string serverIP);
    public delegate void WelComeMessage(string message);
    public delegate void GameInfoUpdate(Game gameInfo);
    public delegate void PlayerLeftGame(IGameClient clientObject);
    public delegate void StartGameServer(Game gameInfo);
    public delegate bool PlayerAlive();

    [Serializable]
    public class EventsClass : EventsManager
    {        
        GamePlayer m_Player = null;

        public event BackUpServerIPUpdate BackUpServerIPUpdateHandler;
        public event WelComeMessage WelComeMessageHandler;
        public event GameInfoUpdate GameInfoUpdateHandler;
        public event PlayerLeftGame PlayerLeftHandler;
        public event StartGameServer StartGameServerHandler;
        public event PlayerAlive PlayerAliveHandler;
                
        public override GamePlayer Player
        {
            get
            {
                return m_Player;
            }
            set
            {
                m_Player = value;
            }
        }

        public override void SendBackUpServerIPToPlayer(string serverIP)
        {
            if (this.BackUpServerIPUpdateHandler != null)
            {
                this.BackUpServerIPUpdateHandler(serverIP);
            }
        }
        public override void SendWelcomeMessageToPlayer(string message)
        {
            if (this.WelComeMessageHandler != null)
            {
                this.WelComeMessageHandler(message);
            }
        }
        public override void PlayerLeft(IGameClient clientObject)
        {
            if (this.PlayerLeftHandler != null)
            {
                this.PlayerLeftHandler(clientObject);
            }
        }
        public override void GameInfoUpdate(Game gameInfo)
        {
            if (this.GameInfoUpdateHandler != null)
            {
                this.GameInfoUpdateHandler(gameInfo);
            }
        }

        public override void StartBackUpGameServer(Game gameInfo)
        {
            if (this.StartGameServerHandler != null)
            {
                this.StartGameServerHandler(gameInfo);
            }
        }

        public override bool IsPlayerAlive()
        {
            if (this.PlayerAliveHandler != null)
            {
                return this.PlayerAliveHandler();
            }
            else
            {
                return false;
            }
        }
        //public override void GameStart(IClientImplement playerObject)
        //{
        //    if (this.GameStartHandler != null)
        //    {
        //        this.GameStartHandler(playerObject);
        //    }
        //}
    }
}
